<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>复合查询 | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'compound-queries.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/compound-queries.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/compound-queries.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/compound-queries.html" rel="nofollow" target="_blank">../en/compound-queries.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch 权威指南 [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="query-dsl.html">查询领域特定语言(Query DSL)</a></span>
»
<span class="breadcrumb-node">复合查询</span>
</div>
<div class="navheader">
<span class="prev">
<a href="query-filter-context.html">« query 和 filter 上下文</a>
</span>
<span class="next">
<a href="query-dsl-bool-query.html">bool 查询 »</a>
</span>
</div>
<div class="chapter">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="compound-queries"></a>复合查询 (compound queries)
</h2>
</div></div></div>
<p>
复合查询包裹其他复合或叶子查询，要么组合它们的结果和分数以改变它们的行为，要么从 query 切换到 filter 上下文。
</p>
<p>该组中的查询包括：</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<a class="xref" href="query-dsl-bool-query.html" title="Boolean query"><code class="literal">bool(布尔)</code> 查询</a>
</span>
</dt>
<dd>
用于组合多个叶子查询子句或复合查询子句的默认查询，如<code class="literal">must</code>、<code class="literal">should</code>、<code class="literal">must_not</code> 或 <code class="literal">filter</code>子句。

<code class="literal">must</code> 和 <code class="literal">should</code> 子句将它们的分数组合在一起，且匹配的子句越多越好；而 <code class="literal">must_not</code> 和 <code class="literal">filter</code> 子句在 filter 上下文中执行。
</dd>
<dt>
<span class="term">
<a class="xref" href="query-dsl-boosting-query.html" title="Boosting query"><code class="literal">boosting</code> 查询</a>
</span>
</dt>
<dd>
返回与 <code class="literal">positive (肯定)</code> 查询匹配的文档，但同时也会降低与 <code class="literal">negative (否定)</code> 查询匹配的文档的分数。
</dd>
<dt>
<span class="term">
<a class="xref" href="query-dsl-constant-score-query.html" title="Constant score query"><code class="literal">constant_score(常量分数)</code> 查询</a>
</span>
</dt>
<dd>
包裹另一个查询，但只在 filter 上下文中执行查询。

所有匹配的文档都被赋予相同的“常数”<code class="literal">_score</code>。
</dd>
<dt>
<span class="term">
<a class="xref" href="query-dsl-dis-max-query.html" title="Disjunction max query"><code class="literal">dis_max</code> 查询</a>
</span>
</dt>
<dd>
接受多个查询并返回与任何查询子句匹配的任何文档的查询。

虽然 <code class="literal">bool</code> 查询组合了所有匹配查询的分数，但是 <code class="literal">dis_max</code> 查询使用单个最佳匹配查询子句的分数。
</dd>
<dt>
<span class="term">
<a class="xref" href="query-dsl-function-score-query.html" title="Function score query"><code class="literal">function_score</code> 查询</a>
</span>
</dt>
<dd>
使用函数修改主查询返回的分数，以考虑流行度(popularity)、新近度(recency)、距离(distance)或使用脚本(script)实现的自定义算法等因素。
</dd>
</dl>
</div>





</div>
<div class="navfooter">
<span class="prev">
<a href="query-filter-context.html">« query 和 filter 上下文</a>
</span>
<span class="next">
<a href="query-dsl-bool-query.html">bool 查询 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>